from flask import Flask, request, jsonify

from javascript.Main import Main

from javascript.Fuc import return_ans, look_project

app = Flask(__name__)


@app.route('/')
def hello_world():  # put application's code here
    value = request.args.get('value')
    try:
        re = return_ans(value)
        return jsonify({"ans": re[0], "su": 1, "list": re[1]})
    except Exception as err:

        return jsonify({"su": 0})


# 查询项目详情 并判断此用户是否已经购买

@app.route('/get_project')
def get_project():
    re = 1
    key_pro = request.args.get("key_pro")
    try:
        lit = look_project(key_pro)
    except Exception as err:
        re = 0
    return jsonify({'list': lit[0], "user_buy": lit[1], 're': re})


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000)
